<html>
<head><meta charset="utf-8"><title>looking for the  syntax description document of HIR and MIR · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html">looking for the  syntax description document of HIR and MIR</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222967614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222967614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jilin <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222967614">(Jan 16 2021 at 07:51)</a>:</h4>
<p>I am going to do research on HIR and MIR, but I can't find any direct syntax description on these languages, like the datatype or function definition.  <br>
Does  anyone got some documents about the syntax of HIR and MIR?</p>



<a name="222971171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222971171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222971171">(Jan 16 2021 at 09:20)</a>:</h4>
<p>HIR and MIR don't have an actual syntax. They are just internal datatstructures. For HIR you should take a look at <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Crate.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Crate.html</a>. For MIR you should take a look at <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Body.html</a>. Note that HIR is only for the current crate and not for dependencies. MIR is only for function bodies; potentially from other crates.</p>



<a name="222971545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222971545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222971545">(Jan 16 2021 at 09:30)</a>:</h4>
<p>HIR and MIR might not have <em>concrete</em> syntax, but they are certainly descriptions of a syntax that could be described by an abstract data structure like an AST. I too am curious about this question; something like an on-paper description of the syntax in abstracted style would be ideal, but somehow I doubt that such a thing currently exists</p>



<a name="222971606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222971606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222971606">(Jan 16 2021 at 09:32)</a>:</h4>
<p>Unfortunately the rustc data structures are not exactly optimized for readability, and the dev guide mostly just tells you that HIR is a thing and points to the docs</p>



<a name="222984964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222984964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222984964">(Jan 16 2021 at 14:45)</a>:</h4>
<p><span class="user-mention" data-user-id="271719">@Mario Carneiro</span> what do you mean by "descriptions of a syntax"? Like they describe an theoretical subset of Rust, sort of like Core in Haskell?</p>



<a name="222984976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222984976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222984976">(Jan 16 2021 at 14:45)</a>:</h4>
<p>Yes</p>



<a name="222984978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222984978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222984978">(Jan 16 2021 at 14:45)</a>:</h4>
<p>I think this would be a great project btw, <span class="user-mention" data-user-id="116266">@Santiago Pastorino</span> has wanted something like this for a while</p>



<a name="222984994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222984994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222984994">(Jan 16 2021 at 14:46)</a>:</h4>
<p>Like I can imagine the rules being written in a paper somewhere, except that it would probably bust the page limit of most venues</p>



<a name="222985040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985040">(Jan 16 2021 at 14:46)</a>:</h4>
<p>-Z unpretty=hir is sort of close but not general and not formal</p>



<a name="222985148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985148">(Jan 16 2021 at 14:48)</a>:</h4>
<p>Is it even a subset? My impression was that it's just a more elaborated version of rust concrete syntax</p>



<a name="222985178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985178">(Jan 16 2021 at 14:49)</a>:</h4>
<p>It doesn't include things like <code>async</code> and <code>if</code> I think, those are removed in rustc_hir_lowering</p>



<a name="222985211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985211">(Jan 16 2021 at 14:49)</a>:</h4>
<p>But also it is not <em>exactly</em> an AST because I think it uses indexes a lot, so you can get into cycles if you try hard enough</p>



<a name="222985281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985281">(Jan 16 2021 at 14:50)</a>:</h4>
<p>I've seen Haskell talks by Simon Peyton-Jones before where he makes a big deal about how surprisingly small the Core language is. I guess the "minimal core" analogue in Rust is MIR, but what makes haskell different in that it can desugar down to a small subset before typechecking?</p>



<a name="222985311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222985311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222985311">(Jan 16 2021 at 14:51)</a>:</h4>
<p><span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span> I don't think anyone has done a comparison</p>



<a name="222987730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222987730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222987730">(Jan 16 2021 at 15:32)</a>:</h4>
<p>I thought haskell desugars after typechecking and does typechecking on the full user facing syntax.</p>



<a name="222994357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/222994357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#222994357">(Jan 16 2021 at 17:33)</a>:</h4>
<p>That's right, GHC type checks on the front-end AST, not Core.</p>



<a name="223002839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/looking%20for%20the%20%20syntax%20description%20document%20of%20HIR%20and%20MIR/near/223002839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/looking.20for.20the.20.20syntax.20description.20document.20of.20HIR.20and.20MIR.html#223002839">(Jan 16 2021 at 20:05)</a>:</h4>
<p>And MIR is also not a subset of Rust because it has constructs that don't exist in Rust, e.g. <code>goto</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>